import random

class richman_building:
  '''Richman building class.

  Richman_building consists of element location, btype, level and value.
  Method:
  __init__(self, i_loc, i_type, i_level, i_value);
  upgrade;
  degrade;
  destroy;
  '''
#  self.location = 0 # Building location(in richman, just a cycle list)
#  self.btype = 0 # Building type: 0-free block 1-park 2-free block
#  self.level = 0 # Building level. It starts with 0, with highest 3.
#  self.value = 0 # value of each level
#  self.ownerid = -1 # owner id
#  self.baseprice = 100 # land base price
  build_num = 0
  
  # Initialize the building property
  def __init__(self, i_loc, i_type, i_level, i_value, i_ownerid):
    self.location = i_loc
    self.btype = i_type
    self.level = i_level
    self.value = i_value
    self.ownerid = i_ownerid # -1: not owned yet
    self.baseprice = 100
    richman_building.build_num += 1
  
  # Selling the building
  def sell(self, i_ownerid):
    self.ownerid = i_ownerid
  
  # Upgrade building  
  def upgrade(self):
    if self.btype == 1:
      print '''Sorry, park can't be upgraded.'''
    elif self.btype <> 1 and self.level < 3:
      self.level += 1
      self.value = 1.5 * self.value
    else:
      print 'The building has been upgraded to the highest level.'
      
  # Degrade building  
  def degrade(self):
    if self.btype == 1:
      print '''Sorry, park can't be degraded.'''
    else:    
      self.level -= 1
      self.value = (2.0/3) * self.value 

  # Destroy building. If park is destroyed, we can build\
  # on the block.
  def destroy(self):
    self.btype = 0
    self.level = 0
  
  # Show rich man building status
  def show_status(self):
    print 'Location: %d, Type: %d, Level: %d, Value: %d, Owner: %d.' \
    %(self.location, self.btype, \
    self.level, self.value, self.ownerid)
  
  # Show building overview
  def show_buildingoverview(self):
    print 'Building overview:\n Total building num: %d.' %(richman_building.build_num)
    
class richman_player:
  ''' Richman player class.

  richman_player consists of location, name, 
  Method:
  
  '''
  player_num = 0

  # Init a player
  def __init__(self, i_playerid, i_location, i_status, i_name, i_fund):
    self.playerid = i_playerid
    self.location = i_location
    self.status = i_status
    self.name = i_name
    self.fund = i_fund
    richman_player.player_num +=1

  # Roll dice
  def roll_dice(self):
    ret = random.randint(1, 6)
    return ret

  # Move around the map
  def move(self, i_step, i_maprange):
    self.location = (self.location + i_step)%i_maprange
  
  # Buy land
  def buy_land(self, i_builiding):
    if i_builiding.ownerid == -1:
      self.fund -= i_builiding.baseprice
      i_builiding.ownerid = self.playerid
    else:
      print 'This is not a virgin land, you can not buy it.'
  
  # Upgrade building
  def upgrade_building(self, i_building):
    self.fund -= i_building.value * 0.5
    i_building.upgrade()
    print 'Upgrade building Done.'

  # Destroy and degrade building. 
  def degrade_building(self, i_building, i_type = 0):
    i_building.degrade()
    print 'Building degrade Done.'

  # Show status
  def show_status(self):
    print 'ID: %d, Location: %d, Status: %d, Name: %s, Funds: %d' \
    %(self.playerid, self.location, self.status,\
    self.name, self.fund)
  
  # Show player overview
  def show_playeroverview(self):
    print 'Player overview:\n Total player num: %d.' %(richman_player.player_num)

#def richman_demo():
  

#Initialize map with 4 buildings and 2 players
#Block
blocka = richman_building(0, 0, 0, 100, -1);
blockb = richman_building(0, 1, 0, 100, -1);
blockc = richman_building(0, 2, 0, 100, -1);
blockd = richman_building(0, 3, 0, 100, -1);
#player
playera = richman_player(1, 0, 0, 'Alice', 1000);
playerb = richman_player(2, 0, 0, 'Bob', 1000);

blocka.show_buildingoverview();
playera.show_playeroverview();

playera.show_status();
playerb.show_status();



